package com.ruoyi.web.controller.linkage.linkageStrategy;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.linkage.Vo.LinkageEventVo;
import com.ruoyi.linkage.domain.LinkageEventRecord;
import com.ruoyi.linkage.service.ILinkageEventRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 联动事件记录Controller
 *
 * @author pengjie
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/linkage/record")
public class LinkageEventRecordController extends BaseController
{
    @Autowired
    private ILinkageEventRecordService linkageEventRecordService;

    /**
     * 查询联动事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('linkage:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestBody LinkageEventVo LinkageEventVo)
    {
        startPage();
        List<LinkageEventRecord> list = linkageEventRecordService.queryLinkageEventRecordList(LinkageEventVo);
        return getDataTable(list);
    }

    /**
     * 导出联动事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('linkage:record:export')")
    @Log(title = "联动事件记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LinkageEventRecord linkageEventRecord)
    {
        List<LinkageEventRecord> list = linkageEventRecordService.selectLinkageEventRecordList(linkageEventRecord);
        ExcelUtil<LinkageEventRecord> util = new ExcelUtil<LinkageEventRecord>(LinkageEventRecord.class);
        util.exportExcel(response, list, "联动事件记录数据");
    }

    /**
     * 获取联动事件记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('linkage:record:query')")
    @GetMapping(value = "/{linkageEventRecordId}")
    public AjaxResult getInfo(@PathVariable("linkageEventRecordId") String linkageEventRecordId)
    {
        return success(linkageEventRecordService.selectLinkageEventRecordByLinkageEventRecordId(linkageEventRecordId));
    }

    /**
     * 新增联动事件记录
     */
    @PreAuthorize("@ss.hasPermi('linkage:record:add')")
    @Log(title = "联动事件记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LinkageEventRecord linkageEventRecord)
    {
        return toAjax(linkageEventRecordService.insertLinkageEventRecord(linkageEventRecord));
    }

    /**
     * 修改联动事件记录
     */
    @PreAuthorize("@ss.hasPermi('linkage:record:edit')")
    @Log(title = "联动事件记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LinkageEventRecord linkageEventRecord)
    {
        return toAjax(linkageEventRecordService.updateLinkageEventRecord(linkageEventRecord));
    }

    /**
     * 删除联动事件记录
     */
    @PreAuthorize("@ss.hasPermi('linkage:record:remove')")
    @Log(title = "联动事件记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkageEventRecordIds}")
    public AjaxResult remove(@PathVariable String[] linkageEventRecordIds)
    {
        return toAjax(linkageEventRecordService.deleteLinkageEventRecordByLinkageEventRecordIds(linkageEventRecordIds));
    }
}
